package com.ecube.mqtt.page.listener.chargelistener;

import com.ecube.mqtt.page.listener.pilechargelistener.PileChargeStartResultListener;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ChargeStartResultPageListener implements ActionListener {
    private JComboBox env;
    private JTextField gunid;
    private JComboBox guncode;

    private JTextField externalCode;
//    private JTextField vehicletext;
//    private JTextField vintext;
    private JFrame start;
    private  String path;
    public ChargeStartResultPageListener(JFrame start,
                                         JComboBox env,
                                         JTextField externalCode,
                                         JTextField gunid,
                                         JComboBox guncode,
                                         String path) {
        this.start = start;
        this.env = env;
        this.externalCode = externalCode;
        this.gunid = gunid;
        this.guncode = guncode;
        this.path = path;
//        this.vehicletext = vehicletext;
//        this.vintext = vintext;
    }

    public void actionPerformed(ActionEvent e) {
        start.dispose();

        Dimension dim2 = new Dimension(100, 30);
        Dimension dim3 = new Dimension(300, 30);
        Font font = new Font("宋体",Font.PLAIN,18);

        //生成新界面
        JFrame startpageres = new JFrame();
        startpageres.setSize(500, 700);
        startpageres.setTitle("启动结果模拟");//设置窗体标题
        startpageres.setDefaultCloseOperation(2);
        startpageres.setLocationRelativeTo(null);
        startpageres.setFont(font);  //宋体，正常风格，14号字体
        //实例化FlowLayout流式布局类的对象，指定对齐方式为居中对齐组件之间的间隔为10个像素
        FlowLayout fl = new FlowLayout(FlowLayout.RIGHT,30,30);
        //实例化流式布局类的对象
        startpageres.setLayout(fl);

        //实例化JLabel标签对象，该对象显示“账号”
        JLabel labname = new JLabel("环境：");
        labname.setFont(font);
        //将labname标签添加到窗体上
        startpageres.add(labname);
        startpageres.add(env);

        //实例化JLabel标签对象，该对象显示“账号”
        JLabel externalname = new JLabel("站ID：");
        externalname.setFont(font);
        //将labname标签添加到窗体上
        startpageres.add(externalname);
        startpageres.add(externalCode);

        //实例化JLabel标签对象，该对象显示“账号”
        JLabel stationname = new JLabel("枪ID：");
        stationname.setFont(font);
        //将labname标签添加到窗体上
        startpageres.add(stationname);
        startpageres.add(gunid);

        //实例化JLabel标签对象，该对象显示“账号”
        JLabel vehicle = new JLabel("AB枪：");
        vehicle.setFont(font);
        startpageres.add(vehicle);
        startpageres.add(guncode);

        //实例化JLabel标签对象，该对象显示“result”
        JLabel resultname = new JLabel("result：");
        resultname.setFont(font);
        //将labname标签添加到窗体上
        startpageres.add(resultname);

        JComboBox result = new JComboBox();
        result.setPreferredSize(dim3);//设置除顶级容器组件以外其他组件的大小
        result.setFont(font);
        result.addItem("1-成功");
        result.addItem("2-失败");
        result.setSelectedItem("2-失败");
        //env.getSelectedItem().toString()
        startpageres.add(result);


        //实例化JLabel标签对象，该对象显示“result”
        JLabel resonname = new JLabel("reson：");
        resonname.setFont(font);
        //将labname标签添加到窗体上
        startpageres.add(resonname);

        JComboBox reson = new JComboBox();
        reson.setPreferredSize(dim3);//设置除顶级容器组件以外其他组件的大小
        reson.setFont(font);
        reson.addItem("null");
        reson.addItem("1-站控处于本地模式，无法启动");
        reson.addItem("2-架载机离线");
        reson.addItem("3-架载机故障");
        reson.addItem("4-充电枪未插入车辆");
        reson.addItem("5-检测到电池已充满");
        reson.addItem("6-充电枪正在充电中");
        reson.addItem("7-架载机模式不正确");
        reson.addItem("8-架载机模式不正确");
        reson.addItem("9-启动指令参数异常");
        reson.setSelectedItem("1");
        //env.getSelectedItem().toString()
        startpageres.add(reson);

        //实例化JButton组件
        JButton startResultButton = new JButton();
        //设置按键的显示内容
        startResultButton.setText("   点击启动   ");
        startResultButton.setFont(new Font("宋体",Font.PLAIN,18));
        //设置按键大小
        startResultButton.setSize(dim3);
        startpageres.add(startResultButton);

        ChargeStartResultListener chargeStartResult = new ChargeStartResultListener(startpageres,
                env,
                externalCode,
                gunid,
                guncode,
                result,
                reson,
                path);
        startResultButton.addActionListener(chargeStartResult);

        //实例化JButton组件
        JButton chargeReturnFirstPageButton = new JButton();
        //设置按键的显示内容
        chargeReturnFirstPageButton.setText("   返回首页   ");
        chargeReturnFirstPageButton.setFont(new Font("宋体",Font.PLAIN,18));
        //设置按键大小
        chargeReturnFirstPageButton.setSize(dim3);
        startpageres.add(chargeReturnFirstPageButton);


        BackListener chargeBack = new BackListener(startpageres, path);
        chargeReturnFirstPageButton.addActionListener(chargeBack);

        startpageres.setResizable(false);
        startpageres.setVisible(true);


    }
}